﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FTchina;

public partial class smstask_ChangePSw : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string result = string.Empty;
        string jsoncallback = FTchina.basic.SafeRequest(Request["jsoncallback"]);

        string uname = FTchina.basic.SafeRequest(Request["Uname"]);
        string oldPsw = FTchina.basic.SafeRequest(Request["oldPsw"]);
        string newPsw = FTchina.basic.SafeRequest(Request["newPsw"]);
        if (CheckUser(uname, oldPsw))
        {
            if (ChangPsw(uname, newPsw))
            {
                LogNet.LogBLL.info(uname + "修改密码成功！" + newPsw + "IP" + basic.GetUserIp());
                result="修改密码成功！";
            }
            else
            {
                result="修改密码失败，请稍候再试！";
            }
        }
        else
        {
            LogNet.LogBLL.info(uname + "修改密码失败，原用户名密码错误！" +oldPsw+"-----"+ newPsw + "IP" + basic.GetUserIp());
            result="原用户名密码错误";
        }

        string re = jsoncallback + "([{\"R\":\"True\"},"
      + "{\"result\":\"" + result + "\"}"

      + "])";
        Response.Write(re);
    }

    private bool ChangPsw(string uname, string newPsw)
    {
        string Sql = "update  SenderList set psw='{1}' where sendername='{0}' ";
        return shujuku.ExecuteSql(string.Format(Sql, uname, newPsw));
    }


    /// <summary>
    /// 检查用户名密码
    /// </summary>
    /// <param name="uname"></param>
    /// <param name="oldPsw"></param>
    /// <returns></returns>
    private bool CheckUser(string uname, string oldPsw)
    {
        string Sql = "select * from  SenderList where sendername='{0}' and psw='{1}'";
        return shujuku.testread(string.Format(Sql, uname, oldPsw));
    }
}